﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtWidgets/QWidget>
#include <QtWidgets>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QTextCodec>
#include <QMessageBox>
#include <windows.h>
#include <dbt.h>
#include <QMutex>
#include <QString>
#include <QSettings>
#include <QDebug>

#include "strpass.h"
#include "mysql.h"
#include "en_data.h"
#include "de_data.h"
#include "showresult.h"

#define VERSION "vLock4_WriteDevdTool_V1.16"
#define PASSWORD "flyscale168"
#define G_BATTERYCHARGEIN_CONSUME_TIME(x)  (tr("请用卤素灯照射太阳能板，等待：<font color=red><b>%1s</b></font>").arg(x))
#define AT_IMEI_STR               "AT+CGSN\r\n"

namespace Ui {
	class MainWindow;
}

typedef enum
{
    STEP_SlrChrgDtcton_ENGINEER = 0,
    STEP_READ_IEMI,
    STEP_READ_ENGINEER,
    STEP_READ_VERSION_ID,
    STEP_WRITE_SIM_ID,
    STEP_READ_SIM_ID,
	STEP_WRITE_DEVICE_ID,
	STEP_READ_DEVICE_INFO,
	STEP_PACKET_DATA,
	STEP_UPDATE_DATA,
	STEP_INIT_DEVICE_PW,
    STEP_Cnfgur_Ip,
	STEP_MAX,
}SoftWare_Step;

class MainWindow : public QMainWindow,public QAbstractNativeEventFilter
{
	Q_OBJECT

public:
	explicit MainWindow(QWidget *parent = 0);
	~MainWindow();
	virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *);//USB插拔检测 zhangyh
	void Delay(unsigned short int ms);

public:
	void initActionsConnections();
	void stop_process();

public:
	void showresult_cusid(void);

public:	//配置
	void read_settings();
	void write_settings();

public://串口
	void serialPort_config();
	void serialBaud_config();
	bool serialOpen();
	bool serialClose();
	void parse_receive_data();

private slots://自定义 槽
	void serialReadData();
	void serial_time_out();

private slots://菜单 槽
	void on_actionAbout_triggered();
	void on_actionSetting_triggered();

private slots://按钮 click 槽
	void on_openserial_pushButton_clicked();
	void on_opensql_pushButton_clicked();
	void on_start_pushButton_clicked();
	void on_cuscode_lineEdit_textChanged(const QString &arg1);
private:
    bool on_judgeSnsql_mysqlMzClient(QString snInfo);
    void on_opensql_mysqlClient();

private:
	Ui::MainWindow *ui;
	QSerialPort *serial;
	en_data *endata;
	de_data *dedata;
	QByteArray serialReceiveData;
	mysql *mysqlClient;
    mysql *mysqlMzClient;
	QTimer *m_time_out_serial;
	unsigned int m_time_out_serial_count;
	unsigned int process_flag;
    bool is_first_rev_error;//接收 设备信息 允许 两次错误 zhangyh；

    QMessageBox *m_message_box;
    QSettings *writelog;
    int chrgDtctntms;
    bool IsShow;
};

#endif // MAINWINDOW_H
